from classfile.attribute_info import AttributeInfo


class LocalVariableTableEntry:
    def __init__(self, startPc, length, nameIndex, descriptorIndex, index):
        self.startPc = startPc
        self.length = length
        self.nameIndex = nameIndex
        self.descriptorIndex = descriptorIndex
        self.index = index


class LocalVariableTableAttribute(AttributeInfo):
    def __init__(self):
        super().__init__()
        self.localVariableTable = []

    def readInfo(self, clsReader):
        localLength = int.from_bytes(clsReader.readU16(), "big")
        for i in range(localLength):
            self.localVariableTable.append(LocalVariableTableEntry(
                int.from_bytes(clsReader.readU16(), "big"),
                int.from_bytes(clsReader.readU16(), "big"),
                int.from_bytes(clsReader.readU16(), "big"),
                int.from_bytes(clsReader.readU16(), "big"),
                int.from_bytes(clsReader.readU16(), "big")
            ))
